#include <iostream>
#include "/home/ssx/code/0118/FreeWay/FreeWay.h"
#include "test.h"
#include "config001.h"
using namespace std;

void freeway2Brain_data(void * argp, const char * buf , int len)
{

    char * a =  new char[len];
    memcpy(a, buf , len);
    LOG(INFO) << "Brain received: " << a;

    delete a;
    a = 0;
}

const std::map<std::string, std::string> & freeway_getmap_from_brain(void * argp)
{
    return config001::getInstance()->getConfigMap();
}


void initlog(int type){
 FLAGS_logbufsecs = 0;
 if(type == SERVER)
    FLAGS_log_dir = "/home/ssx/code/0118/logs/freewaylogs_server";
 else
    FLAGS_log_dir = "/home/ssx/code/0118/logs/freewaylogs_client";
 google::InitGoogleLogging("FreeWay");
}

int main()
{
    cout << "2016/03/03 version 1.0.2" << endl;
    cout << "only users own access admission can receive message..." << endl;

    int freeWayType = 0;

    cout << "what type do you need, server or client ? [0/1]" << endl;
    cin >> freeWayType;


    config001::getInstance()->init();
    config001::getInstance()->loadConfig();

    //cout << "Freeway module configuration: " << endl;
    if(freeWayType == 0)
        freeWayType = SERVER;
    else
        freeWayType = CLIENT;

    initlog(freeWayType);

    FreeWayInit(0, freeWayType);
    FreeWayStart();


    test t;
    t.activate();
    while(1)
    {

    }

    return 0;
}
